﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Globalization;
using Libs.HR;

public partial class Pages_Hr_Family_Add : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        AppUtils.CheckLogin();
        Title = Title + " - Thêm mới người thân";
        if (!IsPostBack)
        {
            init();
        }
    }

    private void init()
    {
        var _Employee = new Employees() { EmployeeID = AppUtils.Request("id") };
        _Employee = _Employee.Get();
        if (_Employee == null) Response.Redirect(Constant.ADMIN_PATH + Resources.Url.EmployeesList);

        lblEmployee.Text = _Employee.LastName + " " + _Employee.FirstName;

        // Quan hệ
        var _FamilyType = new FamilyType();
        drpFamilyType.DataSource = _FamilyType.GetTList();
        drpFamilyType.DataBind();
        drpFamilyType.Items.Insert(0, new ListItem("Chọn quan hệ:", "0"));
    }

    protected void btAdd_Click(object sender, EventArgs e)
    {
        var _Family = new Family();
        _Family.EmployeeID = AppUtils.Request("id");
        _Family.FirstName = txtFirstName.Text;
        _Family.LastName = txtLastName.Text;
        _Family.TypeID = Convert.ToInt32(drpFamilyType.SelectedValue);
        _Family.BirthDay = txtBirthDay.Text.Trim();
        _Family.Address = txtAddress.Text.Trim();
        _Family.Description = txtDescription.Text.Trim();
        _Family.Add();

        Response.Redirect(Constant.ADMIN_PATH + Resources.Url.EmployeesEdit + "?id=" + _Family.EmployeeID.ToString());
    }

    protected void btCancel_Click(object sender, EventArgs e)
    {
        Response.Redirect(Constant.ADMIN_PATH + Resources.Url.EmployeesEdit + "?id=" + Request["id"]);
    }
}
